<template>
  <el-dialog
    :visible.sync="dialogVisible"
    width="300px"
    top="30vh"
    :before-close="handleClose"
  >
    <el-form ref="signForm" size="mini" :model="signForm" :rules="rules">
      <el-form-item prop="skuType" label="是否系列品">
        <!-- <el-radio-group v-model="signForm.skuType">
          <el-radio v-for="item in skuType" :key="item.value" :label="item.value">{{ item.label }}</el-radio> -->
        <!-- <el-radio :label="3">系列品</el-radio> -->
        <!-- </el-radio-group> -->
        <el-switch
          v-model="signForm.skuType"
          active-text="是"
          inactive-text="否"
          active-value="2"
          inactive-value="1"
        />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="handleClose">取 消</el-button>
      <el-button size="mini" type="primary" :loading="loading" @click="subFrom">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { sign } from '@/api/coi/onlineTaskAPI/sku'
import { skuType } from '@/views/coi/commonJs/dictionary'

export default {
  name: 'Sign',
  props: {
    signForm: {
      type: Object,
      default() {
        return { skuType: 1, idList: [] }
      }
    }
  },
  data() {
    return {
      dialogVisible: false,
      loading: false,
      skuType,
      rules: {
        skuType: [{ required: true, message: '请选择需要打标的类型', trigger: 'blur' }]
      }
    }
  },
  methods: {
    handleClose() {
      this.$refs.signForm.clearValidate()
      this.dialogVisible = false
    },
    subFrom() {
      this.$refs.signForm.validate(_ => {
        if (!_) return
        this.signRequest()
      })
    },
    async signRequest() {
      try {
        this.loading = true
        await sign(this.signForm)
        this.$message({
          type: 'success',
          message: '标记SKU类型成功！'
        })
        this.$emit('savaSuccess')
        this.handleClose()
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/ .el-dialog .el-dialog__body{
  padding-bottom: 0;
}
</style>
